/**
 * Created by liyun on 2017/12/27.
 * liyunpeng0110@live.com
 */

'use strict';
angular.module('myapp.FetchDataService', []).factory('FetchDataService', function ($http, $rootScope, $cordovaVibration, $cordovaToast, $timeout, $state, $myconfig) {
    var coryzaData = null;
    var coryzaModeData = null;
    var upKeepData = null;
    var upKeepModeData = null;
    return {
        getCoryzaData: function () { //鼻腔保养数据
            return coryzaData;
        },
        getUpKeepData: function () { //焕颜宝保养数据
            return upKeepData;
        },
        getCoryzaModeData: function () { //鼻腔保养数据
            return coryzaModeData;
        },
        getUpKeepModeData: function () { //焕颜宝保养数据
            return upKeepModeData;
        },

        initData: function () {
            var _this = this;
            $http.get($myconfig.api.base_host + '/device/device_info?device_id=1')
                .then(function (res) {
                    for (var i = 0; i < res.data.data.mode.length; i++) {
                        res.data.data.mode[i].img_all = [];
                        res.data.data.mode[i].img_half = [];
                        res.data.data.mode[i].img_no = [];
                        if (res.data.data.mode[i].strength == 1) {
                            var a = 0,
                                b = 1,
                                c = 2;
                            res.data.data.mode[i].img_all.length = a;
                            res.data.data.mode[i].img_half.length = b;
                            res.data.data.mode[i].img_no.length = c;
                        } else if (res.data.data.mode[i].strength == 1.5) {
                            var a = 1,
                                b = 0,
                                c = 2;
                            res.data.data.mode[i].img_all.length = a;
                            res.data.data.mode[i].img_half.length = b;
                            res.data.data.mode[i].img_no.length = c;
                        } else if (res.data.data.mode[i].strength == 2 || res.data.data.mode[i].strength == 2.5) {
                            var a = 1,
                                b = 1,
                                c = 1;
                            res.data.data.mode[i].img_all.length = a;
                            res.data.data.mode[i].img_half.length = b;
                            res.data.data.mode[i].img_no.length = c;
                        } else if (res.data.data.mode[i].strength == 3 || res.data.data.mode[i].strength == 3.5) {
                            var a = 2,
                                b = 0,
                                c = 1;
                            res.data.data.mode[i].img_all.length = a;
                            res.data.data.mode[i].img_half.length = b;
                            res.data.data.mode[i].img_no.length = c;
                        } else if (res.data.data.mode[i].strength == 4 || res.data.data.mode[i].strength == 4.5) {
                            var a = 2,
                                b = 1,
                                c = 0;
                            res.data.data.mode[i].img_all.length = a;
                            res.data.data.mode[i].img_half.length = b;
                            res.data.data.mode[i].img_no.length = c;
                        } else if (res.data.data.mode[i].strength == 5) {
                            var a = 3,
                                b = 0,
                                c = 0;
                            res.data.data.mode[i].img_all.length = a;
                            res.data.data.mode[i].img_half.length = b;
                            res.data.data.mode[i].img_no.length = c;
                        }
                    }
                    coryzaData = res.data.data;


                    $http.get($myconfig.api.base_host + '/device/device_info?device_id=2')
                        .then(function (res) {
                            for (var i = 0; i < res.data.data.mode.length; i++) {
                                res.data.data.mode[i].img_all = [];
                                res.data.data.mode[i].img_half = [];
                                res.data.data.mode[i].img_no = [];
                                if (res.data.data.mode[i].strength = 1) {
                                    var a = 0, b = 1, c = 2;
                                    res.data.data.mode[i].img_all.length = a;
                                    res.data.data.mode[i].img_half.length = b;
                                    res.data.data.mode[i].img_no.length = c;
                                } else if (res.data.data.mode[i].strength == 1.5) {
                                    var a = 1, b = 0, c = 2;
                                    res.data.data.mode[i].img_all.length = a;
                                    res.data.data.mode[i].img_half.length = b;
                                    res.data.data.mode[i].img_no.length = c;
                                } else if (res.data.data.mode[i].strength == 2 || res.data.data.mode[i].strength == 2.5) {
                                    var a = 1, b = 1, c = 1;
                                    res.data.data.mode[i].img_all.length = a;
                                    res.data.data.mode[i].img_half.length = b;
                                    res.data.data.mode[i].img_no.length = c;
                                } else if (res.data.data.mode[i].strength == 3 || res.data.data.mode[i].strength == 3.5) {
                                    var a = 2, b = 0, c = 1;
                                    res.data.data.mode[i].img_all.length = a;
                                    res.data.data.mode[i].img_half.length = b;
                                    res.data.data.mode[i].img_no.length = c;
                                } else if (res.data.data.mode[i].strength == 4 || res.data.data.mode[i].strength == 4.5) {
                                    var a = 2, b = 1, c = 0;
                                    res.data.data.mode[i].img_all.length = a;
                                    res.data.data.mode[i].img_half.length = b;
                                    res.data.data.mode[i].img_no.length = c;
                                } else if (res.data.data.mode[i].strength == 5) {
                                    var a = 3, b = 0, c = 0;
                                    res.data.data.mode[i].img_all.length = a;
                                    res.data.data.mode[i].img_half.length = b;
                                    res.data.data.mode[i].img_no.length = c;
                                }
                            }
                            upKeepData = res.data.data;
                        })
                });


            //详细理疗数据 比如焕颜宝rgb设置等
            $http.get($myconfig.api.base_host + '/device/list_device_b')
                .then(function (res) {
                    for (var i = 0; i < res.data.data.length; i++) {
                        if (res.data.data[i].name == '金鼻光') {
                            coryzaModeData = res.data.data[i];
                        }else if (res.data.data[i].name == '焕颜宝') {
                            upKeepModeData = res.data.data[i];
                        }
                    }
                });
        }

    };
});
